package com.jerry.mingxing.ui.store;

import android.content.Context;
import android.net.Uri;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.facebook.drawee.view.SimpleDraweeView;
import com.jerry.mingxing.R;
import com.jerry.mingxing.bean.StoreBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/9/1.
 */
public class RecyclerBrandAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>implements View.OnClickListener {

    private List<StoreBean.DataBean.RegionBrandsBean> totallist ;
    private Context context;
    private LayoutInflater inflater;
    private MyInter onItemClick;
    public interface MyInter{
        void onItemClick(View view , StoreBean.DataBean.RegionBrandsBean bean);
    }

    public RecyclerBrandAdapter( List<StoreBean.DataBean.RegionBrandsBean> totallist,Context context) {
        this.totallist=totallist;
        this.context = context;
        this.inflater = LayoutInflater.from(context);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.mycontentviewrecyclerview_brand_item, parent, false);
        MyHolder mholder = new MyHolder(view);

        view.setOnClickListener(this);
        return mholder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
       MyHolder myHolder= (MyHolder) holder;
        myHolder.itemView.setTag(totallist.get(position));
        myHolder.mycontentviewrecyclerviewBranItemSdv.setImageURI(Uri.parse(totallist.get(position).getComponent().getPicUrl()));
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getItemCount() {
        return totallist.size();
    }

    @Override
    public void onClick(View v) {
        if (onItemClick!=null){
            onItemClick.onItemClick(v, (StoreBean.DataBean.RegionBrandsBean) v.getTag());
        }
    }
    public void setonMyClickListener(MyInter mylistener ){
        this.onItemClick=mylistener;
    }


    static class MyHolder extends RecyclerView.ViewHolder {
         SimpleDraweeView mycontentviewrecyclerviewBranItemSdv;
        public MyHolder(View itemView) {
            super(itemView);
            mycontentviewrecyclerviewBranItemSdv= (SimpleDraweeView) itemView.findViewById(R.id.mycontentviewrecyclerview_bran_item_sdv);
        }
    }

    public void reloadData(List list){
        totallist=list;
        notifyDataSetChanged();
    }
}
